// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1

AndroidItem {
    id: _root
    width: 720 * viewScale
    height: 1134 * viewScale
    mouseAccepted: false

    property bool isViewing: false

    property string launcherPath: ""            //ランチャー
    signal clicked(int key)

    property real animWidthFrom: 0
    property real animWidthTo: 0
    property real animXFrom: 0
    property real animXTo: 0
    property real animHeightFrom: 0
    property real animHeightTo: 0
    property real animYFrom: 0
    property real animYTo: 0
    property int zoomDuration: 200

    onIsViewingChanged: {
        if(_anim.running === true){
            _anim.stop();
        }
        _bg.visible = false;
        if(isViewing === true){

            _animWidth.from  = width * 3
            _animWidth.to = width
            _animX.from = -1 * (width * 3 - width) / 2
            _animX.to = 0
            _animHeight.from = height * 3
            _animHeight.to = height
            _animY.from = -1 * (height * 3 - height) / 2
            _animY.to = 0

            _anim.start();
        }else{
            _animWidth.from  = width
            _animWidth.to = width * 3
            _animX.from = 0
            _animX.to = -1 * (width * 3 - width) / 2
            _animHeight.from = height
            _animHeight.to = height * 3
            _animY.from = 0
            _animY.to = -1 * (height * 3 - height) / 2

            _anim.start();

        }
    }

    //背景
    Image{
        id: _bg
        x: 0
        y: 0
        width: parent.width
        height: parent.height

        source: _root.launcherPath
//        fillMode: Image.PreserveAspectCrop
        smooth: true

    }

    // アイコンとかフレーム
    Image{
        id: _frame
        x: 0
        y: 0
        width: parent.width
        height: parent.height
        source: "images/launcher_icons.png"
        fillMode: Image.PreserveAspectCrop
        smooth: true
    }

    SequentialAnimation{
        id: _anim
        running: false

        ScriptAction{
            script: {
                _root.visible = isViewing ? true : _root.viewScale
            }
        }
        ParallelAnimation{
            NumberAnimation{
                id: _animWidth
                target: _frame
                property: "width"
                from: animWidthFrom
                to: animWidthTo
                duration: zoomDuration
            }
            NumberAnimation{
                id: _animX
                target: _frame
                property: "x"
                from: animXFrom
                to: animXTo
                duration: zoomDuration
            }
            NumberAnimation{
                id: _animHeight
                target: _frame
                property: "height"
                from: animHeightFrom
                to: animHeightTo
                duration: zoomDuration
            }
            NumberAnimation{
                id: _animY
                target: _frame
                property: "y"
                from: animYFrom
                to: animYTo
                duration: zoomDuration
            }
        }
        ScriptAction{
            script: {
                _bg.visible = true;
                _root.visible = isViewing ? _root.viewScale : false
            }
        }
    }
}
